﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using frag_boardgame;

namespace Website.BoardWebControl
{
    public partial class MoveWebControl : System.Web.UI.UserControl
    {

        public delegate void movePlayerDelegate (Direction direction, int steps);
        public event movePlayerDelegate OnTryMove;

        public delegate void endTurnDelegate();
        public event endTurnDelegate OnEndTurn;

        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        public int GetSteps()
        {
            int steps;

            if (int.TryParse(StepsLabel.Text, out steps))
            {

            }
            else
            {
                steps = 1;
            }

            return steps;

        }

        protected void ButtonDown_Click(object sender, ImageClickEventArgs e)
        {
            if (OnTryMove != null) 
                OnTryMove(Direction.Down,GetSteps());
        }

        protected void ButtonUp_Click(object sender, ImageClickEventArgs e)
        {
            if (OnTryMove != null)
                OnTryMove(Direction.Up, GetSteps());
        }

        protected void ButtonRight_Click(object sender, ImageClickEventArgs e)
        {
            if (OnTryMove!= null)
                OnTryMove(Direction.Right, GetSteps());
        }

        protected void ButtonLeft_Click(object sender, ImageClickEventArgs e)
        {
            if (OnTryMove != null)
                OnTryMove(Direction.Left, GetSteps());
        }

        protected void EndTurn_Click(object sender, ImageClickEventArgs e)
        {

            if (OnEndTurn != null)
                OnEndTurn();
               
        }

        protected void MoreButton_Click(object sender, ImageClickEventArgs e)
        {
            int steps = GetSteps();
            
            steps = steps + 1;
            if (steps > 9)
                steps = 9;
            

            StepsLabel.Text = steps.ToString();

        }

        protected void LessButton_Click(object sender, ImageClickEventArgs e)
        {
            int steps = GetSteps();

            steps = steps - 1;
            if (steps < 1)
                steps = 1;


            StepsLabel.Text = steps.ToString();
        }
    }
}